import 'package:extended_image/extended_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutterlib/common/style/meterial_design_icons.dart';
import 'package:flutterlib/common/style/quhui_style.dart';
import 'package:flutterlib/common/utils/utils.dart';

class UserInfoWidget extends StatelessWidget {
  final String image;
  final VoidCallback onPressed;
  final double width;
  final double height;
  final EdgeInsetsGeometry padding;

  const UserInfoWidget(
      {Key key,
      this.image,
      this.onPressed,
      this.width = 30.0,
      this.height = 30.0,
      this.padding})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return RawMaterialButton(
        materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
        padding:
        padding ?? const EdgeInsets.only(top: 4.0, right: 5.0, left: 5.0),
        constraints: const BoxConstraints(minWidth: 0.0, minHeight: 0.0),
        child: new ClipOval(
          child: TextUtil.isEmpty(image) ?

          Image(
            image: AssetImage(R.DEFAULT_USER_ICON),
            fit: BoxFit.fitWidth,
            width: width,
            height: height,
          )
          : FadeInImage(
            placeholder: AssetImage(
              R.DEFAULT_USER_ICON,
            ),
            image: ExtendedNetworkImageProvider(
              image,
              cache: true,
              retries: 1,
            ),
            //预览图
            fit: BoxFit.cover,
            width: width,
            height: height,
          ),
        ),
        onPressed: onPressed);
  }
}
